package com.fx.commonuntils;

import lombok.extern.slf4j.Slf4j;


@Slf4j
public class ReturnMessageUtil {
    /**
     * 判断是否成功
     *
     * @param returnMessage
     * @return
     */
    public static boolean isSuccess(com.fx.commonuntils.ReturnMessage<Object> returnMessage) {
        return returnMessage.getCode().equals(ErrorEnum.E_SUCCESS.getErrorCode());
    }

    /**
     * 无异常
     *
     * @param object
     * @return
     */

    public static com.fx.commonuntils.ReturnMessage<Object> success(Object object) {
        com.fx.commonuntils.ReturnMessage<Object> message = new com.fx.commonuntils.ReturnMessage<Object>(ErrorEnum.E_SUCCESS.getErrorCode(), ErrorEnum.E_SUCCESS.getErrorMsg(), object);
        return message;
    }

    /**
     * 无异常 请求成功并有具体内容返回
     *
     * @param object
     * @return
     */

    public static com.fx.commonuntils.ReturnMessage<Object> success(String msg, Object object) {
        com.fx.commonuntils.ReturnMessage<Object> message = new com.fx.commonuntils.ReturnMessage<Object>(ErrorEnum.E_SUCCESS.getErrorCode(), msg, object);
        return message;
    }

    /**
     * 无异常 请求成功并无具体内容返回
     *
     * @return
     */
    public static com.fx.commonuntils.ReturnMessage<Object> success() {
        com.fx.commonuntils.ReturnMessage<Object> message = new com.fx.commonuntils.ReturnMessage<Object>(ErrorEnum.E_SUCCESS.getErrorCode(), ErrorEnum.E_SUCCESS.getErrorMsg(), null);
        return message;
    }

    /**
     * 有自定义错误异常信息
     *
     * @param code
     * @param msg
     * @return
     */
    public static com.fx.commonuntils.ReturnMessage<Object> error(Integer code, String msg) {
        com.fx.commonuntils.ReturnMessage<Object> message = new com.fx.commonuntils.ReturnMessage<Object>(code, msg, null);
        return message;
    }

    /**
     * 有自定义错误异常信息：来自自定义类型
     *
     * @return
     */
    public static com.fx.commonuntils.ReturnMessage<Object> errorWithEum(ErrorEnum errorEnum) {
        com.fx.commonuntils.ReturnMessage<Object> message = new com.fx.commonuntils.ReturnMessage<Object>(errorEnum.getErrorCode(), errorEnum.getErrorMsg(), null);
        return message;
    }

    /**
     * 有自定义错误异常信息：来自exception
     *
     * @param e
     * @return
     */
    public static com.fx.commonuntils.ReturnMessage<Object> errorWithException(Exception e) {
        com.fx.commonuntils.ReturnMessage<Object> message = new com.fx.commonuntils.ReturnMessage<Object>(ErrorEnum.E_SYSTEM_BUSY.getErrorCode(), ErrorEnum.E_SYSTEM_BUSY.getErrorMsg(), null);
        return message;
    }
}
